'''
Created on 12.09.2009

@author: ankstoo
'''

from pygs.logger import logger
from pygs.services.security.encoder import encoderInstance
from pygs.services.security.authenticationSecured import AuthenticationStrategy

class AuthenticationStrategyLoginPassword(AuthenticationStrategy):
    '''            
    '''
    def checkUser(self, params):
        result = AuthenticationStrategy.checkUser(self, params)
        userName = params["user"]
        passwd = params["passwd"]
        logger.log("Try to login user '%s'." % userName)        
        userParams = self.authentication.persistence().getUserParamsByUserName(userName, ["userId", "passwd"])
        if userParams:
            result["userExists"] = True
            result["userId"] = userParams["userId"]
            if userParams["passwd"] == encoderInstance.encodeSHA1(passwd):
                result["userValid"] = True
        return result
        
#AuthenticationStrategyLoginPassword.register("lp", True)